<template>
  <div class="empl">
    <ul class="publish-nav">
      <li>
        <a href="javascript:;" :class="{active:isActive==0}" @click.prevent="pubPro">
          发布拍品
        </a>
      </li>
      <li>
        <a href="javascript:;" :class="{active:isActive==1}" @click.prevent="publickSpecial">
          发布专场
        </a>
      </li>
    </ul>

    <router-view></router-view>

    <!--弹出框-->
    <div class="dialog" v-show="isShowDialog">
      <div class="weui-mask"></div>
      <div class="weui-dialog">
        <div class="weui-dialog__bd" v-if="user.type!=1">仅开通店铺的用户才可发布专场，请先申请开店。</div>
        <div class="weui-dialog__bd" v-if="user.type==1">个人认证的用户无法发布发布专场。</div>
        <div class="weui-dialog__ft">
          <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_default" @click.prevent="cancel">取消</a>
          <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary" @click.prevent="toShop" v-if="user.type!=1">立即申请开店</a>
        </div>
      </div>
    </div>

    <footer-vue ref="pubfooter"></footer-vue>
  </div>
</template>

<script>
  import {getUser,setUser,getStatusMapByKey} from '../../assets/js/tools.js';
  import {getUserMsg} from "../../assets/js/getData";
  export default {
    name: "publish",
    data(){
      return {
        user:null,
        isShowDialog:false,
        isActive:null,
        shopAudited:null,//7
        shopAuditting:null,//6
        shopNotPass:null,//1
      }
    },
    created(){
      this.user = getUser();
      let eShopStatus = getStatusMapByKey('eShopStatus');
      this.shopAudited =  eShopStatus.audited.val;//已审核7
      this.shopAuditting =  eShopStatus.auditting.val;//审核中6
      this.shopNotPass =  eShopStatus.notPass.val;//未通过1
      if(this.$route.path=='/publish/publishSpecial'){
        this.isActive = 1;
      }else {
        this.isActive = 0;
      }
    },
    mounted(){
      this.$refs.pubfooter.$refs.pub.className += ' router-link-active';
    },
    methods:{
      pubPro(){
        this.$router.replace({name:'publish.publishLot'});
      },
      //点击切换到发布专场
      publickSpecial(){
        //获取用户信息
        getUserMsg().then(res => {
          if(res.data.reqResult.code>0){
            let data = res.data.data.user;
            //实名认证状态
            if(data.hasOwnProperty("shopAudittingStatus")){
              this.user.shopAudittingStatus = data.shopAudittingStatus;
              setUser(this.user);
              if(this.user.shopAudittingStatus==this.shopAudited){
                this.$router.replace({name:'publish.publishSpecial'});
              }else {
                this.isShowDialog = !this.isShowDialog;
              }
            }else {
              this.isShowDialog = !this.isShowDialog;
            }
          }else {
            Toast(res.data.reqResult.msg);
          }
        })
      },
      //弹出框立即申请开店按钮
      toShop(){
        if(this.user.hasOwnProperty("shopAudittingStatus")){
          if(this.user.shopAudittingStatus == this.shopAuditting){
            this.$router.push({name:'shopAudit'});
          }else if(this.user.shopAudittingStatus == this.shopNotPass){
            this.$router.push({name:'shopFail'});
          }
        }else {
          this.$router.push({name:'shopAut'});
        }
      },
      cancel(){
        this.isShowDialog = !this.isShowDialog;
      }
    }
  }
</script>

<style scoped>
  .empl{
    padding-bottom: 80px;
  }
  .publish-nav{
    display: flex;
    box-sizing: border-box;
  }
  .publish-nav li{
    width: 50%;
    text-align: center;
  }
  .publish-nav a{
    display: inline-block;
    font-size: 0.8rem;
    color: #999999;
    padding: 0.8rem 0.05rem 0.4rem 0.05rem;
    position: relative;
  }
  .publish-nav a.active{
    color: #1A1A1A;
    border-bottom: 4px solid #C50000;
  }
</style>
